/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.border.EtchedBorder;

import soccerscope.model.Ball;
import soccerscope.util.Color2;

public class BallTrainingButton extends JButton {
	private static final long serialVersionUID = -6766831964829889642L;

	private Ball ball;

	private FontMetrics fm;

	private int ballR;

	private int ball2R;

	public BallTrainingButton(Ball ball) {
		super();
		this.ball = ball;
		ball.mode = Ball.STAND;
		this.ballR = (int) (0.15 * 3.6 * 8.0);
		this.ball2R = this.ballR * 2;
		setBorder(new EtchedBorder(EtchedBorder.LOWERED));
		setBorderPainted(true);
	}

	public void setBall(Ball ball) {
		this.ball = ball;
		repaint();
	}

	@Override
	public Dimension getPreferredSize() {
		return getMinimumSize();
	}

	@Override
	public Dimension getMinimumSize() {
		return new Dimension(200, 200);
	}

	@Override
	public void paintComponent(Graphics g) {
		if (this.fm == null) {
			this.fm = this.getFontMetrics(this.getFont());
		}
		Dimension d = getSize();

		g.setColor(Color2.forestGreen);
		g.fillRect(0, 0, d.width, d.height);

		if (!this.ball.isEnable())
			return;

		Font f = g.getFont();
		if (f.isBold()) {
			g.setFont(f.deriveFont(Font.PLAIN));
		}

		int cx = d.width / 2;
		int cy = d.height / 2;
		int x = cx - this.ballR;
		int y = cy - this.ballR;

		Color drawColor = Color2.white;

		// drawball
		g.setColor(drawColor);
		g.fillOval(x, y, this.ball2R, this.ball2R);

	}

}
